import request from '@/utils/request'

export interface DeviceInventory {
  deviceId: number;
  deviceName: string;
  deviceModel: string;
  category: string;
  supplier: string;
  supplierScore: number | null;
}

export interface DeviceInventoryModel {
  isUpdate?: boolean | null;
  deviceId?: number | null;
  deviceName: string | null;
  deviceModel: string | null;
  category: string | null;
  supplier: string | null;
  supplierScore: number | null;
}

export interface DeviceInventoryListResponse {
  current: number;
  total: number;
  pages: number;
  size: number;
  records: DeviceInventory[];
}

export interface Category {
    categoryName?: String| null;
}


export interface DeviceInventoryFormItemConfig {
  type: 'input' | 'datetime' | 'select' | 'number';
  label: string;
  prop: keyof DeviceInventoryModel;
  placeholder?: string;
  inputType?: HTMLInputElement['type'];
  options?: Array<{label: string, value: any}>;
}

export const deviceInventoryApi = {
  getDeviceInventoryList: (params:any) => {
    return request<DeviceInventoryListResponse>({
      method: 'GET',
      url: `/procedure/devices`,
      params: params
    });
  },

  addDevice: (data: DeviceInventoryModel) => {
    return request<string>({
      method: 'POST',
      url: `/procedure/devices`,
      data: data
    });
  },

  updateDevice: (id: number, data: DeviceInventoryModel) => {
    return request<string>({
      method: 'PUT',
      url: `/procedure/devices/${id}`,
      data: data
    });
  },

  deleteDevice: (id: number) => {
    return request<string>({
      method: 'DELETE',
      url: `/procedure/devices/${id}`,
    });
  },

  getCategoryList: () => {
    return request<Category[]>({
      method: 'GET',
      url: `/procedure/devices/categories`,
    });
  },

    listAttachmentsByProfileAndType: (params: { profileId: number, type: number }) => {
      return request<DeviceAttachment[]>({
        method: 'GET',
        url: `/procedure/attachments`,
        params: params
      });
    },
    saveAttachment: (data: DeviceAttachmentDTO) => {
    return request<void>({
      method: 'POST',
      url: `/procedure/attachments`,
      data: data
    });
  },
};


export interface DeviceAttachment {
  attachmentId: number;
  deviceProfileId: number | null;
  attachmentName: string;
  attachmentUrl: string;
  type: number;
  uploadTime: string;
}

export interface DeviceAttachmentDTO {
    deviceProfileId?: number| null;
    attachmentName: string;
    type: number | null;
    attachmentUrl: string|null;
}
